package com.tky.conference.Tree;

import java.util.List;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.tky.conference.R;


public class SimpleTreeListViewAdapter<T> extends TreeListViewAdapter<T> {


	
	public SimpleTreeListViewAdapter(Context context, ListView tree, List<T> datas, int defaultExpandLevel) throws IllegalAccessException, IllegalArgumentException {
		super(context, tree, datas, defaultExpandLevel);
	}



	@Override
	public View getConvertView(Node node, int position, View convertView, ViewGroup parent) {
		
		ViewHolder holder = null;
		if (convertView==null) {
			convertView = mInflater.inflate(R.layout.tree_item, parent, false);
			holder = new ViewHolder();
			holder.mIcon = (ImageView) convertView.findViewById(R.id.item_icon);
			holder.mText = (TextView) convertView.findViewById(R.id.item_text);
			holder.isCheck= (CheckBox) convertView.findViewById(R.id.isCheck);
			convertView.setTag(holder);
		}else {
			holder = (ViewHolder) convertView.getTag();
		}
		
		if (node.getIcon() == -1) {
			holder.mIcon.setVisibility(View.INVISIBLE);
		}else {
			holder.mIcon.setVisibility(View.VISIBLE);
			holder.mIcon.setImageResource(node.getIcon());
		}

		if (node.isLeaf()){
			holder.isCheck.setVisibility(View.VISIBLE);
			holder.isCheck.setChecked(node.isChecked());
		}else {
			holder.isCheck.setVisibility(View.GONE);
		}
		holder.mText.setText(node.getName());

		return convertView;
	}

	private class ViewHolder{
		ImageView mIcon;
		TextView mText;
		CheckBox isCheck;
	}

}
